<?php
	$searchquery = $_GET['searchquery'];
	$messages = PDO_FetchAll("SELECT message.*,urlpreview.url,urlpreview.site,urlpreview.title,urlpreview.desc,urlpreview.image,attachment.name as fname,attachment.type as ftype,attachment.size as fsize,attachment.preview as fpreview, reminder.date as reminder, reminder.active FROM message LEFT JOIN urlpreview ON urlpreview.message_id = message.id LEFT JOIN attachment ON attachment.message_id = message.id LEFT JOIN reminder ON reminder.message_id = message.id WHERE message.text LIKE \"%$searchquery%\"");
	
	echo " 
	<div class='chat-header'><div>".$loc_string['search_results']." $searchquery</div></div>
        <div class='messages'>";
	
	include "system/getmessage.php";
	foreach ($messages as $message){
		echo renderMessage($message);
	}
	
	echo "</div>";
?>
